package com.mid;

/**
 * Created by Lxk on 2019/7/7.
 */
public class Solution230 {

    private Integer res = null;
    private Integer count = 0;

    private void midVisit(TreeNode cur, Integer k) {
        if (cur == null) {
            return;
        }
        midVisit(cur.left, k);
        count++;
        if (count.equals(k)) {
            res = cur.val;
        }
        midVisit(cur.right, k);
    }

    public int kthSmallest(TreeNode root, int k) {
        midVisit(root, k);
        return res;
    }

    public static void main(String[] args) {
        TreeNode node = new TreeNode(3);
        TreeNode node2 = new TreeNode(1);
        TreeNode node5 = new TreeNode(4);
        TreeNode node6 = new TreeNode(2);
        node.left = node2;
        node.right = node5;
        node2.right = node6;
        Solution230 solution230 = new Solution230();
        System.out.println(solution230.kthSmallest(node, 1));
    }

}
